package com.fan.request;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;


public class Servlet1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //使用request对象获取请求行的信息
        //1.获取请求方法
        String method = request.getMethod();
        System.out.println("请求方式为" + method);
        //2.获取客户端的ip地址
        String remoteAddr = request.getRemoteAddr();
        System.out.println("客户端的ip地址是" + remoteAddr);
        //3.获取项目部署的路径
        String contextPath = request.getContextPath();
        System.out.println("项目部署的路径是" + contextPath);
        //4.获取请求的url：统一资源定位符http：//localhost：8080/
        String url = request.getRequestURL().toString();
        System.out.println("此次请求的url是"+url);
        //5.获取请求的uri：统一资源标识符，在url的基础上省略了服务器路径
        //htttp：//localhost：8080
        String uri = request.getRequestURI();
        System.out.println(uri);
    }
}
